#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e3 + 10;
int arr[N];
int n;
int sqr(int x)
{
	return x * x;
}
int main()
{
	cin >> n;
	int ans = 1e9;
	for (int i = 0; i < n; i++)cin >> arr[i];
	for (int i = 0; i <= 83; i++) {
		int cost = 0;
		for (int j = 0; j < n; j++) {
			if (arr[j] < i) {
				cost += sqr(i - arr[j]);
			}
			else if (arr[j] > i + 17) {
				cost += sqr(arr[j] - i - 17);
			}
		}
		ans = min(ans, cost);
	}
	cout << ans << endl;
	return 0;
}